package com.zking.myservlet.order;

import com.zking.dao.OrderDao;
import com.zking.util.RedirectMsg;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.Part;
import java.io.IOException;

@WebServlet("/manage/OrderUpdate")
public class OrderUpdate extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html");
        resp.setCharacterEncoding("UTF-8");

        int eoId = Integer.parseInt(req.getParameter("orderId"));
        int eoStatus = Integer.parseInt(req.getParameter("status"));

        req.setAttribute("pageName", RedirectMsg.orderListPageName);
        req.setAttribute("url", RedirectMsg.orderListUrl);
        if(OrderDao.alterOrderStatus(eoId, eoStatus)){
            req.setAttribute("msg", RedirectMsg.alterOrderStatusSuccess);
            req.getRequestDispatcher("redirect.jsp").forward(req, resp);
        }else{
            req.setAttribute("msg", RedirectMsg.alterOrderStatusError);
            req.getRequestDispatcher("redirect.jsp").forward(req, resp);
        }
    }
}
